#ifndef _DEV_EEPROM_H_
#define _DEV_EEPROM_H_

#include "data_type.h"

#define DEV_EEPROM_DELAY    5     /* wait 5ms befor next operation */

/* EEPROM 容量种类 (Kbit) */
#define DEV_EEPROM_TYPE_01    0
#define DEV_EEPROM_TYPE_02    1
#define DEV_EEPROM_TYPE_04    2
#define DEV_EEPROM_TYPE_08    3
#define DEV_EEPROM_TYPE_16    4
#define DEV_EEPROM_TYPE_32    5
#define DEV_EEPROM_TYPE_64    6
#define DEV_EEPROM_TYPE_128   7
#define DEV_EEPROM_TYPE_256   8
#define DEV_EEPROM_TYPE_512   9

/* 定义使用的 EEPROM 类型 */
#ifndef DEV_EEPROM_TYPE
#define DEV_EEPROM_TYPE DEV_EEPROM_TYPE_02      /* must config */
#endif

typedef struct DEV_RTDRV_EEPROM
{
    INIT_STATUS              init_status;                       /* 设备初始化状态 */
    struct rt_i2c_bus_device *i2c_bus;      /* I2C总线设备句柄 */
    uint8_t                  fix_addr;      /* 固定从机地址 */
    uint8_t                  sub_addr;      /* 地址增补 (对于 <= 16 的存储器 有效) */
    uint8_t                  capacity_kbit; /* 容量kbit */
    uint16_t                 max_addr;      /* 最大地址 */
    uint16_t                 page_byte;     /* 每页字节数 */
    uint16_t                 page_nbr;      /* 页个数 */
} dev_rtdrv_eeprom;
typedef dev_rtdrv_eeprom *dev_rtdrv_eeprom_t;

/* EEPROM 初始化 */
RET_STATUS dev_eeprom_init(void);
/* 显示EEPROM设备信息 */
void dev_eeprom_show_info(void);
/* EEPROM 写一个字节 */
RET_STATUS dev_eeprom_write_one_byte(uint16_t wr_addr, uint8_t data);
/* EEPROM 读一个字节 */
RET_STATUS dev_eeprom_read_one_byte(uint16_t rd_addr, uint8_t *data);
/* EEPROM 写buf */
RET_STATUS dev_eeprom_write_buf(uint16_t wr_addr, uint8_t *wr_buf, uint16_t byte_nbr);
/* EEPROM 读buf */
RET_STATUS dev_eeprom_read_buf(uint16_t rd_addr, uint8_t *rd_buf, uint16_t byte_nbr);
/* EEPROM 写float */
RET_STATUS dev_eeprom_write_float(uint16_t wr_addr, float data);
/* EEPROM 读float */
RET_STATUS dev_eeprom_read_float(uint16_t rd_addr, float *data);

#endif
